{% extends "lbforum/base_site.html" %}

{% load i18n %}
{% load lbforum_filters %}
{% load lbforum_tags %}
{% load avatar_tags %}
{% load pagination_tags %}

{% block title %}
    {{ topic.subject }} - {{ LBFORUM_TITLE }}
{% endblock %}

{% block content_right_bar %}
    {% include 'lbforum/widgets/cur_user_profile.html' %}
{% endblock %}

{% block content_content %}
    {% autopaginate posts TOPIC_PAGE_SIZE %}
    <div class="box">
        {% with post=topic.post %}
        <div class="cell" style="min-height: 73px;">
            <div class="fr snow" style="padding-left: 10px; padding-bottom: 10px;">
                <a href="{% url lbforum_user_profile post.posted_by.pk %}">{% avatar post.posted_by %}</a>
            </div>
            <span class="bigger">
                <a href="{% url lbforum_index %}">{{ LBFORUM_TITLE }}</a>
                <span class="chevron">&raquo;</span>
                <a href="{{ topic.forum.get_absolute_url }}">{{ topic.forum.name }}</a>
            </span>
            <h1>{{topic}}</h1>
            <small class="fade">
                By 
                <a href="{% url lbforum_user_profile post.posted_by.pk %}">{{post.posted_by.username}}</a>
                at {{ topic.get_last_post.update|lbtimesince }},
                {{topic.num_views}} hits
				{% if user.is_staff %}
				<span>|</span>
				<span>
					<a href="{% url lbforum_update_topic_attr_as_not topic.id 'distillate' %}">
						{% if topic.level >= 60 %} {% trans "undistillate" %} {% else %} {% trans "distillate" %} {% endif %}
					</a>
				</span>
				<span>
					<a href="{% url lbforum_update_topic_attr_as_not topic.id 'close' %}">
						{% if topic.closed %} {% trans "unclose" %} {% else %} {% trans "close" %} {% endif %}
					</a>
				</span>
				<span>
					<a href="{% url lbforum_update_topic_attr_as_not topic.id 'hide' %}">
						{% if topic.hidden %} {% trans "unhide" %} {% else %} {% trans "hide" %} {% endif %}
					</a>
				</span>
				<span>
					<a href="{% url lbforum_delete_topic topic.id %}" onclick="return confirm('{% trans "Do you want to delete it?" %}')">{% trans "delete" %}</a>
				</span>
				{% endif %}
            </small>
        </div>
        <div class="inner">
            <div class="content topic_content">
                {% include 'lbforum/inc_post_content.html' %}
            </div>
        </div>
        <div class="inner" id="topic-post-footer">
            <div class="fr">
                {% if user == post.posted_by or user.is_staff %}
                    <span>
                        <a href="{% url lbforum_post_edit post.pk %}">{% trans "edit" %}</a>
                    </span>
                    |
                {% endif %}
                <span>
                    <a href="{% url lbforum_new_replay topic.pk %}?qid={{post.pk}}">{% trans "quote" %}</a>
                </span>
                {% if user.is_authenticated %}
                    <span>
                        <a class="newpost" href="{% url lbforum_new_replay topic.pk %}">
                            {% trans "Post reply" %}
                        </a>
                    </span>
                {% endif %} 
            </div>
            &nbsp;
        </div>
    {% endwith %}
</div>

<div class="sep20"></div>

{% if not posts %}
<div align="center" class="glass"><div class="inner"><span class="white">{% trans "No Reply" %}</span></div></div>
{% else %}
<div class="box">
    <div class="cell">
        <div class="fr">
        </div>
        <span class="fade">
            {% trans "Posts" %} [ {% page_range_info page_obj %} ]
            <span class="snow">|</span>
            {% trans "Last post" %} {{ topic.get_last_post.update|lbtimesince }}
        </span>
    </div>
    <div id="replies">
        {% for post in posts %}     
            {% include 'lbforum/inc_post_detail.html' %}
        {% endfor %}
    </div>
    <div class="inner">
        {% paginate %}	
    </div>
</div>
{% endif %}

{% if user.is_authenticated %}
<div class="sep20"></div>
<div class="box" id="quick-reply-box">
    <form action="{% url lbforum_new_replay topic.pk %}" accept-charset="utf-8" method="post" class="frm-form">
        <div class="cell"><div class="fr fade"><a class="dark" href="#Top">Top&uarr;</a></div>
            <span class="fade">
                {% trans "Quick reply to this topic" %}
            </span>
        </div>
        <div class="cell">
            <textarea id="reply_content" name="message" class="mll"></textarea>
            <div class="sep10"></div>
            <div id="e" class="fr fade"></div>
            {% csrf_token %} 
            <input type="submit" value="{% trans "Submit" %}" name="submit" class="super normal button">
            <input type="submit" value="{% trans "Preview" %}" name="preview" class="super normal button">
        </div>
    </form>

    <div class="inner">
        <span class="fade" style="font-size: 120%">
            <small>{% trans "You may use" %}: </small>
            <a class="node" target="_blank" title="Help with: BBCode" href="http://fluxbb.org/forums/help/bbcode/" class="exthelp">BBCode</a>
            <a class="node" target="_blank" title="Help with: Images" href="http://fluxbb.org/forums/help/img/" class="exthelp">Images</a>
        </span>
    </div>
</div>
{% endif %}
{% endblock %}

{% block footer_js %}
    <script type="text/javascript" src="{{ STATIC_URL }}lbforum/scripts/jquery.min.js"></script>
    <script type="text/javascript">
        $('.entry-attachments-img-s a').click(function() {
            var p = $(this).parent();
            p.hide();
            p.next().show()
            return false;
        })
        $('.content a').attr({ target: "_blank" });
    </script>
{% endblock %}
